require 'RMagick'

class Filter < ActiveRecord::Base
belongs_to :user

  def execute(input,name)
    image =  Magick::Image.from_blob(input.file).first
    self.body.each do |line|
      begin
        eval line
      rescue NameError => filter
        self.find_by_name('#{filter.name}').execute
      end
      image.write(name)
      return name
    end

  end
end
